//
//  HMSportTrackingLine.m
//  HMBest22
//
//  Created by Apple on 17/1/10.
//  Copyright © 2017年 Apple. All rights reserved.
//  单词运动的数据 (大概一秒)

#import "HMSportTrackingLine.h"

@implementation HMSportTrackingLine
- (instancetype)initWithStartLocation:(CLLocation *)startLocation andEndLocation:(CLLocation *)endLocation
{
    self = [super init];
    if (self) {
        _startLocation = startLocation;
        _endLocation = endLocation;
    }
    return self;
}


- (HMSportPolyline *)polyline
{
    CLLocationCoordinate2D coords[2];
    coords[0] = self.startLocation.coordinate;// 起点
    
    coords[1] = self.endLocation.coordinate;// 终点
//    NSLog(@"平均速度%f    距离%f     时间%f",self.speed,self.distance,self.time);
    CGFloat speedR = 8 * self.speed / 255.0;
    // 设置颜色
    UIColor *color = [UIColor colorWithRed:speedR green:1 blue:0 alpha:1];
    return [HMSportPolyline polylineWithCoordinates:coords count:2 andColor:color];
}



- (double)speed
{
    // 速度的单位 m/s   用户习惯的单位是 km / h
    // 转换单位   1000m / 3600s
    // 汽车  120    骑行    30     跑步  13
    return (self.startLocation.speed + self.endLocation.speed) * 0.5 * 3.6;
}

- (double)distance
{
    return [self.endLocation distanceFromLocation:self.startLocation] * 0.001;
}

- (double)time
{
    return [self.endLocation.timestamp timeIntervalSinceDate:self.startLocation.timestamp];
}
@end
